<%@ page import="com.example.cdpbookstore.service.OrderService" %>
<%@ page import="com.example.cdpbookstore.service.impl.OrderServiceImpl" %>
<%@ page import="com.example.cdpbookstore.pojo.entity.Order" %>
<%@ page import="java.util.List" %>
<%@ page import="com.example.cdpbookstore.pojo.entity.Customer" %>
<%@ page import="java.util.ArrayList" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    OrderService orderService = new OrderServiceImpl();
    Customer customer = (Customer) session.getAttribute("customer");
    List<Order> orderList;
    if (customer == null) {
        orderList = new ArrayList<>();
        response.sendRedirect("login.jsp");
    } else {
        orderList = orderService.listByCustomerId(customer.getId());
    }
    pageContext.setAttribute("orderList", orderList);
%>
<!DOCTYPE html>
<html lang="zh-Hans-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>布克书店 - 我的订单</title>

    <link rel="icon" type="image/png" href="image/web-icon.png">
    <link rel="stylesheet" type="text/css" href="lib/font-awesome-6.5.2/css/all.css">
    <link rel="stylesheet" type="text/css" href="lib/bootstrap-4.6.2/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="css/common/com-a.css">
    <link rel="stylesheet" type="text/css" href="css/common/com-b.css">
    <link rel="stylesheet" type="text/css" href="css/order.css">
</head>

<body>
<div class="main">
    <jsp:include page="common/header1.jsp"/>


    <div class="container">
        <div class="card-header my-3">所有订单</div>
        <table class="table table-light">
            <thead>
            <tr>
                <th scope="col">时间</th>
                <th scope="col">总价</th>
                <th scope="col">取消</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach var="order" items="${orderList}">
                <tr>
                    <td>${order.creationTime}</td>
                    <td>￥${order.totalAmount}</td>
                    <td><a class="btn btn-sm btn-danger" href="cancel-order?id=${order.id}">取消订单</a></td>
                </tr>
                <tr>
                    <td colspan="3">
                        <table class="table table-striped">
                            <tbody>
                            <c:forEach var="detail" items="${order.orderDetailList}">
                                <tr>
                                    <td>
                                        <img alt="" class="img-thumbnail" width="100px" src="img/book/${detail.book.images}">
                                    </td>
                                    <td style="width: 400px;">${detail.book.bookName}</td>
                                    <td style="width: 120px;">￥${detail.unitPrice}</td>
                                    <td style="width: 120px;">x${detail.num}</td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </div>

    <jsp:include page="common/footer1.jsp"/>
</div>
</body>

</html>